//package com.windy.i18n.filter;
//
//
//import com.windy.common.context.LocaleContextHolder;
//import org.springframework.core.Ordered;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * Created by liyufeng on 2022/5/15
// */
//public class TraceOrderedRequestContextFilter extends OncePerRequestFilter implements Ordered {
//    //OrderedRequestContextFilter order=-105
//    private int order = -106;
//    @Override
//    public int getOrder() {
//        return this.order;
//    }
//
//    /**
//     * Returns "false" so that the filter may set up the request context in each
//     * asynchronously dispatched thread.
//     */
//    @Override
//    protected boolean shouldNotFilterAsyncDispatch() {
//        return false;
//    }
//
//    /**
//     * Returns "false" so that the filter may set up the request context in an
//     * error dispatch.
//     */
//    @Override
//    protected boolean shouldNotFilterErrorDispatch() {
//        return false;
//    }
//
//    @Override
//    protected void doFilterInternal(
//            HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
//            throws ServletException, IOException {
//
//        ServletRequestAttributes attributes = new ServletRequestAttributes(request, response);
//        initContextHolders(request, attributes);
//
//        try {
//            filterChain.doFilter(request, response);
//        }
//        finally {
//            resetContextHolders();
//            if (logger.isTraceEnabled()) {
//                logger.trace("Cleared thread-bound request context: " + request);
//            }
//            attributes.requestCompleted();
//        }
//    }
//
//    private void initContextHolders(HttpServletRequest request, ServletRequestAttributes requestAttributes) {
//        LocaleContextHolder.setLocale(request.getLocale());
//        RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);
//        if (logger.isTraceEnabled()) {
//            logger.trace("Bound request context to thread: " + request);
//        }
//    }
//
//    private void resetContextHolders() {
//        LocaleContextHolder.resetLocaleContext();
//        RequestContextHolder.resetRequestAttributes();
//    }
//}
